package com.kinoshita.manager.util;

import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.util.DigestUtils;

/**
 * <p>
 *  密码工具类
 * </p>
 *
 * @author reagan
 * @since 2022-08-31
 */
public class PasswordUtil implements PasswordEncoder {
    /**
     * 加密密码
     * @param charSequence
     * @return String
     */
    @Override
    public String encode(CharSequence charSequence) {
        return DigestUtils.md5DigestAsHex(charSequence.toString().getBytes());
    }

    /**
     * 密码判读
     * @param charSequence
     * @param s
     * @return boolean
     */
    @Override
    public boolean matches(CharSequence charSequence, String s) {
        String encode = DigestUtils.md5DigestAsHex(charSequence.toString().getBytes());
        boolean res = s.equals(encode);
        return res;
    }
}

